package com.sikaryofficial.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.annotation.Repeat;
import com.sikaryofficial.backend.config.TenantFilterProperties;
import com.sikaryofficial.backend.domain.dto.SysDictDataDTO;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleBrandSpecialListReq;
import com.sikaryofficial.backend.domain.dto.resp.brandspecial.BrandSpecialDTO;
import com.sikaryofficial.backend.domain.vo.BrandTenantVO;
import com.sikaryofficial.backend.manager.BrandSpecialManager;
import com.sikaryofficial.backend.manager.information.ArticleFrontEndManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.system.api.model.infomation.ArticleDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌专栏Controller
 *
 * @author qinjinyuan
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/brandSpecial/frontend")
@Api(tags = "V2.5 H5-品牌专栏服务")
public class BrandSpecialFrontendController extends BaseController {
    @Autowired
    private BrandSpecialManager brandSpecialManager;
    @Autowired
    private ArticleFrontEndManager articleManager;
    @Autowired
    private TenantFilterProperties tenantFilterProperties;

    @GetMapping("/brandPlatform")
    @ApiOperation("后台管理-子品牌枚举列表")
    public R<List<SysDictDataDTO>> brandPlatform() {
        List<BrandTenantVO> brandTenantList = tenantFilterProperties.getBrandTenantList();
        List<SysDictDataDTO> result = new ArrayList<>();
        for (BrandTenantVO brandTenantVO : brandTenantList) {
            if (StringUtils.equalsAny(brandTenantVO.getBrandNo(), "CHANNEL", "HISMK")) {
                continue;
            }
            SysDictDataDTO sysDictDataDTO = new SysDictDataDTO();
            result.add(sysDictDataDTO);
            sysDictDataDTO.setDictLabel(brandTenantVO.getBrandNo());
            sysDictDataDTO.setDictDesc(brandTenantVO.getBrandNo());
            sysDictDataDTO.setDictValue(brandTenantVO.getTenantId() + "");
            sysDictDataDTO.setDictType("brand_platform");
        }
        return R.ok(result);
    }

    /**
     * 查询品牌专栏列表
     */
    @PostMapping("/list")
    @ApiOperation("H5-品牌专栏列表")
    @Repeat
    public R<List<BrandSpecialDTO>> listByH5() {
        return R.ok(brandSpecialManager.list());
    }

    /**
     * 获取品牌专栏详细信息
     */
    @ApiOperation("H5-品牌专栏详情")
    @GetMapping(value = "/detail/{brandSpecialId}")
    @Repeat
    public R<BrandSpecialDTO> getInfo(@PathVariable("brandSpecialId") Long brandSpecialId) {
        return R.ok(brandSpecialManager.detail(brandSpecialId));
    }

    /**
     * V2.5 品牌专栏-文章列表
     */
    @PostMapping("/article/listPage")
    @ApiOperation("品牌专栏-文章分页列表")
    @Repeat
    public PageResult<ArticleDTO> brandSpecialPage(@Validated @RequestBody ArticleBrandSpecialListReq req) {
        IPage<ArticleDTO> page = articleManager.brandSpecialPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }
}
